//*********************************************************************
// Copyright (C) 2014 Hell Prototypes / www.hellprototypes.com
// 
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
//********************************************************************
#ifndef __SPI_H
#define __SPI_H

/** **********************************************************/

#define SET_SCK()		setbit(PORT_SPI_OUT,PIN_SPI_SCK)
#define CLR_SCK()		clrbit(PORT_SPI_OUT,PIN_SPI_SCK)

#define TOGGLE_SCK()	togglebit(PORT_SPI_OUT, PIN_SPI_SCK)

#define SET_MOSI()		setbit(PORT_SPI_OUT,PIN_SPI_MOSI)
#define CLR_MOSI()		clrbit(PORT_SPI_OUT,PIN_SPI_MOSI)

#define GET_MISO()		testbit(PORT_SPI_IN,PIN_SPI_MISO)

#define ROM_Active()	clrbit(PORT_CTRL_OUT,PIN_ROM_CS)
#define ROM_Deactive()	setbit(PORT_CTRL_OUT,PIN_ROM_CS)

void spi_init(void);
uint8_t spi_play_one_byte(uint8_t data);
void spi_read_data(uint8_t addr_H, uint16_t addr_L, uint8_t *read_buff, uint16_t len);
uint16_t read_spi_flash_status(void);

#endif
